package id.amikom.jogjabankfinder.activity;

import roboguice.activity.RoboActivity;
import roboguice.inject.InjectView;
import id.amikom.jogjabankfinder.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class MenuUtama extends RoboActivity implements OnClickListener
{
	private int		WIDTH, HEIGHT;
	// linear
	@InjectView(R.id.atasKiriKolom1)
	LinearLayout	linearAtasKiri;
	@InjectView(R.id.atasKananKolom1)
	LinearLayout	linearAtasKanan;
	@InjectView(R.id.tengahKiriKolom1)
	LinearLayout	linearTengahKiri;
	@InjectView(R.id.tengahKananKolom1)
	LinearLayout	linearTengahKanan;
	@InjectView(R.id.bawahKiriKolom1)
	LinearLayout	linearBawahKiri;
	@InjectView(R.id.bawahKananKolom1)
	LinearLayout	linearBawahKanan;

	// button
	@InjectView(R.id.btnLokasiBank)
	Button			btnLokasiBank;
	@InjectView(R.id.btnDirectionBank)
	Button			btnDirectionBank;
	@InjectView(R.id.btnKodeBank)
	Button			btnKodeBank;
	@InjectView(R.id.btnKonversi)
	Button			btnKonversi;
	@InjectView(R.id.btnAbout)
	Button			btnAbout;
	@InjectView(R.id.btnHelp)
	Button			btnHelp;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menuutama);

		WIDTH = this.getWindowManager().getDefaultDisplay().getWidth();
		HEIGHT = this.getWindowManager().getDefaultDisplay().getHeight();

		// setting tinggi dan lebar
		linearAtasKiri.setMinimumWidth(WIDTH / 2);
		linearAtasKiri.setMinimumHeight(HEIGHT / 3);
		linearAtasKanan.setMinimumWidth(WIDTH / 2);
		linearAtasKanan.setMinimumHeight(HEIGHT / 3);

		linearTengahKiri.setMinimumWidth(WIDTH / 2);
		linearTengahKiri.setMinimumHeight(HEIGHT / 3);
		linearTengahKanan.setMinimumWidth(WIDTH / 2);
		linearTengahKanan.setMinimumHeight(HEIGHT / 3);

		linearBawahKiri.setMinimumWidth(WIDTH / 2);
		linearBawahKiri.setMinimumHeight(HEIGHT / 3);
		linearBawahKanan.setMinimumWidth(WIDTH / 2);
		linearBawahKanan.setMinimumHeight(HEIGHT / 3);

		btnAbout.setOnClickListener(this);
		btnDirectionBank.setOnClickListener(this);
		btnHelp.setOnClickListener(this);
		btnKodeBank.setOnClickListener(this);
		btnKonversi.setOnClickListener(this);
		btnLokasiBank.setOnClickListener(this);
	}

	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
			case R.id.btnLokasiBank:
				startActivity(new Intent(this, PetaLokasi.class));
				break;
			case R.id.btnDirectionBank:
				startActivity(new Intent(this, ListBank.class));
				break;
			case R.id.btnKodeBank:
				startActivity(new Intent(this, KodeBank.class));
				break;
			case R.id.btnKonversi:
				startActivity(new Intent(this, Konversi.class));
				break;
			case R.id.btnAbout:
				startActivity(new Intent(this, About.class));
				break;
			case R.id.btnHelp:
				startActivity(new Intent(this, Help.class));
				break;
		}
		finish();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			AlertDialog.Builder alert = new AlertDialog.Builder(this);

			alert.setTitle("Keluar Aplikasi");
			alert.setMessage("Apakah anda ingin keluar ?");
			alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
			{
				@Override
				public void onClick(DialogInterface dialog, int which)
				{
					dialog.cancel();
				}
			});
			alert.setPositiveButton("YES", new DialogInterface.OnClickListener()
			{
				@Override
				public void onClick(DialogInterface dialog, int which)
				{
					finish();
				}
			});
			alert.show();
		}
		return super.onKeyDown(keyCode, event);
	}
}
